package com.example.administrator.fastdream.date;


import com.example.administrator.fastdream.Constant;
import com.example.administrator.fastdream.date.utils.Utils;

public class WXParmas {
    //应用ID
    public String appid = "";
    //商户号
    public String partnerid = "";
    //预支付交易会话ID
    public String prepayid = "";
    //扩展字段
    public String packageValue = "";
    //随机字符串
    public String noncestr = "";
    //时间戳
    public String timestamp = "";
    //签名
    public String sign = "";

    /**
     * @ 调起微信本地sdk支付必须的参数
     * @author zhoupan
     */
    public WXParmas(String prepayid, String sign, String noncestr, String partnerid, String appid, String timestamp) {
        this.appid = appid;
        this.partnerid = partnerid;
        this.prepayid = prepayid;
        this.packageValue = "Sign=WXPay";
        this.noncestr = noncestr;
        this.timestamp = timestamp;
        this.sign = sign;
    }

    private void setSign() {
        this.sign = genSign();
    }

    private void setTimestamp() {
        this.timestamp = String.valueOf(System.currentTimeMillis() / 1000);
    }

    public String genSign() {
        String tempSign = "appid=" + appid +
                "&noncestr=" + noncestr +
                "&package=" + packageValue +
                "&partnerid=" + partnerid +
                "&prepayid=" + prepayid +
                "&timestamp=" + timestamp +
                "&key=" + Constant.KEY;
        return Utils.MD5Encode(tempSign, "utf-8").toUpperCase();
    }

    @Override
    public String toString() {
        return "WXParmas{" +
                "appid='" + appid + '\'' +
                ", prepayid='" + prepayid + '\'' +
                ", partnerid='" + partnerid + '\'' +
                ", packagevalue='" + packageValue + '\'' +
                ", noncestr='" + noncestr + '\'' +
                ", timestamp='" + timestamp + '\'' +
                ", sign='" + sign + '\'' +
                '}';
    }
}
